filename = ARGV.first
script = $0

puts "We're going to erase #{filename}."
puts "If you don't want that,hit CTRL-C(^C)."
puts "If you do want that ,hit RETURN."

print "?"
STDIN.gets

puts "Opening the file..."
target = File.open(filename,'w')

puts "Truncating the file.Goodbye!"
target.truncate(target.size)

puts "Now I'm going to ask you for three lines."
print "line1";  line1 = STDIN.gets.chomp()
print "line2";  line2 = STDIN.gets.chomp()
print "line3";  line3 = STDIN.gets.chomp()

puts "I'm going to write these to the file."

target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")

puts "And finally,we close it."
target.close()

#希望你能理解这里面到底是在干什么？拿到一个文件对象，你就可以操作这个文件，这就和你用文本编辑器打开，修改，保存是一样的，你基本上可以把这个文件对象看成那个文件了，然后对那个对象的操作就是对文件的操作。然后还要多看看文件的api文档，这个一是要用心，二是要多试api里的方法，也可以看看java2s里文件的通常操作是怎么样的。
